<?php
	include "../../public/commom/config.php";
	include "../lock2.php";
	include "../../public/commom/thumb.php";
	include "../../public/commom/commom.php";
	
	if($_POST){
		$name = $_POST["name"];
		$price = $_POST["price"];
		$inventory = $_POST["inventory"];
		$bid = $_POST["brand_id"];
		$shelf = $_POST["shelf"];
		$area_id = $_SESSION["area_id"];
		
		/*图片*/
		$imgsrc = $_FILES["img"]["tmp_name"];//获取图片临时路径
		$fname = $_FILES["img"]["name"];//获取图片名称
		$a = explode(".", $fname);//获取图片后缀名
		$ext = array_pop($a);//
		$dst = $uploadPath . time().mt_rand(). "." . $ext;//随机生成图片名称

		//图片上传成功
		if(move_uploaded_file($imgsrc, $dst)) {
			thumb($dst, 200, 200);//生成缩略图
			$img = basename($dst);//获取带后缀名的图片名称
		}
		
		/*读取店铺id*/
		$sql = "SELECT * FROM store WHERE user_id = " . $_SESSION["user_id"] . "";
		
		$result = mysqli_query($conn, $sql);
		
		while($row = mysqli_fetch_assoc($result)) {
			$store_id = $row["id"];
		}
		
		/*插入商品*/
		$sql1 = "INSERT INTO shop (name, img, price, inventory, shelf, brand_id, area_id, store_id) VALUES ('$name', '$img', '$price', '$inventory', '$shelf', '$bid', '$area_id', '$store_id')";
		
		$result1 = mysqli_query($conn, $sql1);
		
		mysqli_close($conn);
		
		header("Location: ./index.php");
	}
?>